//    Copyright (C) Kherty.  All rights reserved.
using System;
using System.Diagnostics.Contracts;
using System.IO;

namespace OpenLS.Spreadsheet.Formats.Biff.Records
{
    

    internal class WriteAccessRecord : BiffRecord
    {
        public WriteAccessRecord()
        {
            
        }

        public WriteAccessRecord(string userName)
        {
            this.userName = (XLUnicodeString) userName;
        }
        private XLUnicodeString userName;
        protected override void ReadContent(BiffReaderContext context, int length)
        {
            var position = context.BaseStream.Position;
            userName.Read(context.Reader);
            var diff = length - (context.BaseStream.Position - position);
            Contract.Assert(diff >= 0);
            context.ReadBytes((int) diff);
            context.ReadBytes(0);
        }

        internal override BiffRecordType RecordType
        {
            get { return BiffRecordType.WriteAccess; }
        }

        internal override void WriteContent(BiffWriterWorkbookContext context)
        {
            var position = context.Writer.BaseStream.Position;
            userName.Write(context);
            var diff = 112 - (context.Writer.BaseStream.Position - position);
            Contract.Assert(diff >= 0);
            for (int i = 0; i < diff; i++ )
                context.Write((byte)32);

        }
    }
}